package com.example.springboot.controller;

import com.example.springboot.bean.TSCourse;
import com.example.springboot.bean.TSCourseStudent;
import com.example.springboot.bean.TSStudent;
import com.example.springboot.service.CourseService;
import com.example.springboot.service.CourseStudentService;
import com.example.springboot.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by tang on 2017/11/16.
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @Resource
    CourseService courseService;

    @Resource
    StudentService studentService;

    @Resource
    CourseStudentService courseStudentService;


    @RequestMapping("/saveCourseStudent")
    public String saveCourseStudent() {

        TSStudent student = new TSStudent();
        student.setName("Tom");
        TSCourse course = new TSCourse();
        course.setName("语文");

        TSCourseStudent courseStudent = new TSCourseStudent();

        courseService.save(course);
        studentService.save(student);
        courseStudent.setCourse(course);
        courseStudent.setStudent(student);
        courseStudentService.save(courseStudent);

        return "success";
    }


    @RequestMapping("/helloThymeleaf")
    public String helloJsp(Map<String, Object> params, HttpServletResponse response) {
//        response.setHeader("Access-Control-Allow-Origin", "*");
        params.put("name", "Tang");
        return "hello";
    }
}
